import { getlistAll, getlistUser } from '@/api/base'
const state = {
  tableDataUser: {},
  roleList: []
}

const mutations = {
  SET_TABLE: (state, table) => {
    state.tableDataUser = table
  },
  SET_ROLELIST: (state, roles) => {
    state.roleList = roles
  }

}

const actions = {
  settable({ commit }, data) {
    return new Promise((resolve, reject) => {
      getlistUser(data).then((response) => {
        const { data } = response
        commit('SET_TABLE', data)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },
  setrole({ commit }, data) {
    return new Promise((resolve, reject) => {
      getlistAll().then((response) => {
        const { data } = response
        commit('SET_ROLELIST', data.items)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
